package com.chang.cheng.toutiaoserver.login.service.impl;

import com.chang.cheng.toutiaoserver.login.service.ApUserLoginService;
import com.chang.cheng.toutiaoserver.model.common.dtos.ResponseResult;
import com.chang.cheng.toutiaoserver.model.common.enums.AppHttpCodeEnum;
import com.chang.cheng.toutiaoserver.model.jwt.AppJwtUtil;
import com.chang.cheng.toutiaoserver.model.user.pojos.AppUser;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Auther: asus
 * @Date: 2022/01/02 17:30
 * @Description:
 */
@Service
public class ApUserLoginServiceImpl implements ApUserLoginService {
    @Override
    public ResponseResult loginAuthAppV1(AppUser user) {
        Long phone = user.getMobile();
        Integer code=user.getCode();
        //TODO 短信模块返回验证码为returnCode
        Integer returnCode=246810;
        // Integer用==号会异常.
        if (phone!=null&&returnCode.equals(code)){
            user.setPassword("");
            Map<String, Object> map = new HashMap<>();
            map.put("token", AppJwtUtil.getToken(user));
            map.put("user", user);
            return ResponseResult.okResult(map);
        }

        return ResponseResult.errorResult(AppHttpCodeEnum.VERIFICATION_CODE_ERROR);
    }
}
